package org.sdp.pearproject.controller;


import org.sdp.pearproject.controller.custom.*;
import org.sdp.pearproject.dto.request.*;
import org.sdp.pearproject.dto.response.*;

import java.util.List;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName: MemberController
 * @Description:
 * @Author: SDP
 * @Date: 2022-07-18
 * @Version: 1.0
 * Table: pear_member
 * Comment:
 * 用户表
 */
@RestController
@RequestMapping(value = "/member")
public class MemberController extends MemberCustomController {
    static {
        addRequestClass("member", "add", "memberController", MemberController.class, MemberAddRequest.class);
        addRequestClass("member", "add_encrypt", "memberController", MemberController.class, MemberAddRequest.class);

        addRequestClass("member", "update", "memberController", MemberController.class, MemberUpdateRequest.class);
        addRequestClass("member", "update_encrypt", "memberController", MemberController.class, MemberUpdateRequest.class);

        addRequestClass("member", "delete", "memberController", MemberController.class, MemberDeleteRequest.class);
        addRequestClass("member", "delete_encrypt", "memberController", MemberController.class, MemberDeleteRequest.class);

        addRequestClass("member", "query", "memberController", MemberController.class, MemberQueryRequest.class);
        addRequestClass("member", "query_encrypt", "memberController", MemberController.class, MemberQueryRequest.class);

        addRequestClass("member", "list", "memberController", MemberController.class, MemberQueryRequest.class);
        addRequestClass("member", "list_encrypt", "memberController", MemberController.class, MemberQueryRequest.class);

        addRequestClass("member", "count", "memberController", MemberController.class, MemberQueryRequest.class);
        addRequestClass("member", "count_encrypt", "memberController", MemberController.class, MemberQueryRequest.class);

        addRequestClass("member", "stat", "memberController", MemberController.class, MemberQueryRequest.class);
        addRequestClass("member", "stat_encrypt", "memberController", MemberController.class, MemberQueryRequest.class);

    }

    @PostMapping("/add")
    public Integer addMember(@MixRequestBody MemberAddRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("member", "add", request, callFromEncrypt);
        return super.addMember(request);
    }

    @PostMapping("/add_encrypt")
    public String addMemberEncrypt(@MixRequestBody String strRequest) throws Exception {
        MemberAddRequest request = (MemberAddRequest) super.decrypt("member", "add_encrypt", strRequest, MemberAddRequest.class);
        Integer result = addMember(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/update")
    public Integer updateMember(@MixRequestBody MemberUpdateRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("member", "update", request, callFromEncrypt);
        return super.updateMember(request);
    }

    @PostMapping("/update_encrypt")
    public String updateMemberEncrypt(@MixRequestBody String strRequest) throws Exception {
        MemberUpdateRequest request = (MemberUpdateRequest) super.decrypt("member", "update_encrypt", strRequest, MemberUpdateRequest.class);
        Integer result = updateMember(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/delete")
    public Integer deleteMember(@MixRequestBody MemberDeleteRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("member", "delete", request, callFromEncrypt);
        return super.deleteMember(request);
    }

    @PostMapping("/delete_encrypt")
    public String deleteMemberEncrypt(@MixRequestBody String strRequest) throws Exception {
        MemberDeleteRequest request = (MemberDeleteRequest) super.decrypt("member", "delete_encrypt", strRequest, MemberDeleteRequest.class);
        Integer result = deleteMember(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/query")
    public MemberQueryResponse queryMember(@MixRequestBody MemberQueryRequest request, Integer callFromEncrypt) throws Exception {
      super.fixRequest("member", "query", request, callFromEncrypt);
      return super.queryMember(request);
    }

    @PostMapping("/query_encrypt")
    public String queryMemberEncrypt(@MixRequestBody String strRequest) throws Exception {
        MemberQueryRequest request = (MemberQueryRequest) super.decrypt("member", "query_encrypt", strRequest, MemberQueryRequest.class);
        MemberQueryResponse result = queryMember(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/list")
    public List<MemberQueryResponse> listMember(@MixRequestBody MemberQueryRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("member", "list", request, callFromEncrypt);
        if (super.needTotal("member", "list", request)) {
            super.setTotal("member", "list", request, super.countMember(request));
        }
        return super.listMember(request);
    }

    @PostMapping("/list_encrypt")
    public String listMemberEncrypt(@MixRequestBody String strRequest) throws Exception {
        MemberQueryRequest request = (MemberQueryRequest) super.decrypt("member", "list_encrypt", strRequest, MemberQueryRequest.class);
        List<MemberQueryResponse> result = listMember(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/count")
    public Integer countMember(@MixRequestBody MemberQueryRequest request, Integer callFromEncrypt) throws Exception {
      super.fixRequest("member", "count", request, callFromEncrypt);
      return super.countMember(request);
    }


    @PostMapping("/count_encrypt")
    public String countMemberEncrypt(@MixRequestBody String strRequest) throws Exception {
        MemberQueryRequest request = (MemberQueryRequest) super.decrypt("member", "count_encrypt", strRequest, MemberQueryRequest.class);
        Integer result = countMember(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }

    @PostMapping("/stat")
    public BaseStatResponse statMember(@MixRequestBody MemberQueryRequest request, Integer callFromEncrypt) throws Exception {
        super.fixRequest("member", "stat", request, callFromEncrypt);
        return super.statMember(request);
    }

    @PostMapping("/stat_encrypt")
    public String statMemberEncrypt(@MixRequestBody String strRequest) throws Exception {
        MemberQueryRequest request = (MemberQueryRequest) super.decrypt("member", "stat_encrypt", strRequest, MemberQueryRequest.class);
        BaseStatResponse result = statMember(request, 1);
        if (result == null) {
            return null;
        }
        String response = toJSONString(result);

        return super.encrypt(request, response);
    }


}
